Skip to content

Implement max_events per run limit#2986

Merged
shalabhc merged 15 commits into
mainfrom
shalabhc/event-limit-enforcement
Jul 22, 2026
Merged

Implement max_events per run limit#2986
shalabhc merged 15 commits into
mainfrom
shalabhc/event-limit-enforcement

Conversation

@shalabhc

@shalabhc shalabhc commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Enforces the published per-run events limit, which was previously not enforced. The server supplies the limit on the run_started response (separate change); once a run's event log reaches it, the runtime throws MaxEventsExceededError at the top of the replay loop, and the existing terminal-error path records it as run_failed with a new MAX_EVENTS_EXCEEDED code — instead of letting a runaway workflow (e.g. an unbounded step loop) grow the event log without bound.

  • Checked after the log is loaded and before runWorkflow schedules more work; deterministic, so it fails without retry/redelivery and is attributed to user code.
  • Enforced under both the Vercel World (server-supplied limit) and the Local World (WORKFLOW_MAX_EVENTS).
  • Additive and backwards-compatible: older servers/worlds omit the limit ⇒ no enforcement, in either direction.

Testing

  • classify-error.test.tsMaxEventsExceededError classifies as MAX_EVENTS_EXCEEDED.
  • describe-error.test.ts — user attribution + hint for the code.
  • world-testing E2E — a runaway workflow fails with MAX_EVENTS_EXCEEDED via the in-process Local World (WORKFLOW_MAX_EVENTS=10, turbo disabled), no Docker.

Pairs with the server change: vercel/workflow-server#638

@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f70fea4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@workflow/errors Patch
@workflow/core Patch
@workflow/world Patch
@workflow/world-vercel Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/web-shared Patch
@workflow/web Patch
workflow Patch
@workflow/world-local Patch
@workflow/world-postgres Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/vitest Patch
@workflow/world-testing Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/nuxt Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit 81e9dcb · Tue, 21 Jul 2026 21:00:02 GMT · run logs

Backend: vercel · app: nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 129 (+16%) 🔻 315 🔴 (+41%) 🔻 373 🔴 (-8.1%) 456 (-13%) 30
TTFS stream 124 (-8.8%) 206 🔴 (-29%) 💚 227 (-37%) 💚 492 (-39%) 💚 30
TTFS hook + stream 293 (-17%) 💚 461 🔴 (-9.3%) 586 🔴 (+1.7%) 1378 🔴 (+123%) 🔻 30
STSO 1020 steps (1-20) 196 (+15%) 318 🔴 (+20%) 🔻 364 🔴 (+13%) 743 🔴 (+104%) 🔻 19
STSO 1020 steps (101-120) 244 (+18%) 🔻 356 🔴 (+17%) 🔻 456 🔴 (+33%) 🔻 596 🔴 (+26%) 🔻 19
STSO 1020 steps (1001-1020) 599 (+2.2%) 803 🔴 (+12%) 1015 🔴 (+31%) 🔻 1022 🔴 (+25%) 🔻 19
WO 1020 steps 574390 (+9.0%) 574390 (+9.0%) 574390 (+9.0%) 574390 (+9.0%) 1
SL stream latency 76 (±0%) 117 🔴 (+13%) 155 🔴 (-6.6%) 228 🔴 (-5.8%) 30
📜 Previous results (8)

f70fea4

Tue, 21 Jul 2026 18:44:53 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 155 (-85%) 💚 300 🔴 (-74%) 💚 383 🔴 (-70%) 💚 431 (-72%) 💚 30
TTFS stream 154 (-38%) 💚 386 🔴 (-66%) 💚 509 🔴 (-58%) 💚 2386 🔴 (+92%) 🔻 30
TTFS hook + stream 300 (-76%) 💚 507 🔴 (-65%) 💚 731 🔴 (-51%) 💚 2592 🔴 (+60%) 🔻 30
STSO 1020 steps (1-20) 196 (+8.9%) 325 🔴 (+1.6%) 428 🔴 (+18%) 🔻 453 🔴 (+3.9%) 19
STSO 1020 steps (101-120) 240 (+16%) 🔻 415 🔴 (+28%) 🔻 525 🔴 (+38%) 🔻 1034 🔴 (+106%) 🔻 19
STSO 1020 steps (1001-1020) 620 (+24%) 🔻 731 🔴 (+23%) 🔻 869 🔴 (+35%) 🔻 911 🔴 (+24%) 🔻 19
WO 1020 steps 545430 (+24%) 🔻 545430 (+24%) 🔻 545430 (+24%) 🔻 545430 (+24%) 🔻 1
SL stream latency 100 (+1.0%) 156 🔴 (-7.1%) 191 🔴 (+3.8%) 2560 🔴 (+1091%) 🔻 30

6d2ded2

Tue, 21 Jul 2026 04:23:07 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 443 (-38%) 💚 1290 🔴 (+20%) 🔻 1307 🔴 (+19%) 🔻 1424 🔴 (-4.2%) 30
TTFS stream 1209 (+29%) 🔻 1274 🔴 (+23%) 🔻 1286 🔴 (+21%) 🔻 1293 🔴 (+19%) 🔻 30
TTFS hook + stream 1423 (+19%) 🔻 1545 🔴 (+21%) 🔻 1689 🔴 (+29%) 🔻 3424 🔴 (+140%) 🔻 30
STSO 1020 steps (1-20) 166 (-3.5%) 278 🔴 (+14%) 372 🔴 (+30%) 🔻 435 🔴 (+26%) 🔻 19
STSO 1020 steps (101-120) 180 (-6.3%) 244 🔴 (-7.9%) 323 🔴 (-53%) 💚 360 🔴 (-68%) 💚 19
STSO 1020 steps (1001-1020) 468 (+2.0%) 592 🔴 (+17%) 🔻 724 🔴 (+32%) 🔻 3563 🔴 (+430%) 🔻 19
WO 1020 steps 374542 (-1.1%) 374542 (-1.1%) 374542 (-1.1%) 374542 (-1.1%) 1
SL stream latency 83 (+1.2%) 142 🔴 (+15%) 158 🔴 (-1.3%) 246 🔴 (+12%) 30

3a9ff12

Tue, 21 Jul 2026 01:06:57 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 233 (-67%) 💚 1275 🔴 (+19%) 🔻 1316 🔴 (+20%) 🔻 1411 🔴 (-5.0%) 30
TTFS stream 213 (-77%) 💚 1257 🔴 (+21%) 🔻 1278 🔴 (+21%) 🔻 1340 🔴 (+23%) 🔻 30
TTFS hook + stream 540 (-55%) 💚 1482 🔴 (+16%) 🔻 1516 🔴 (+15%) 🔻 1652 🔴 (+16%) 🔻 30
STSO 1020 steps (1-20) 171 (-0.6%) 283 🔴 (+16%) 🔻 310 🔴 (+8.4%) 316 🔴 (-8.4%) 19
STSO 1020 steps (101-120) 175 (-8.9%) 246 🔴 (-7.2%) 317 🔴 (-54%) 💚 543 🔴 (-52%) 💚 19
STSO 1020 steps (1001-1020) 467 (+1.7%) 571 🔴 (+12%) 585 🔴 (+6.4%) 882 🔴 (+31%) 🔻 19
WO 1020 steps 390362 (+3.0%) 390362 (+3.0%) 390362 (+3.0%) 390362 (+3.0%) 1
SL stream latency 90 (+9.8%) 145 🔴 (+17%) 🔻 209 🔴 (+31%) 🔻 307 🔴 (+40%) 🔻 30

3f073da

Mon, 20 Jul 2026 20:27:41 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 1353 🔴 1398 🔴 1464 🔴 30
TTFS stream 1346 🔴 1405 🔴 1449 🔴 30
TTFS hook + stream 1693 🔴 1707 🔴 1776 🔴 30
STSO 1020 steps (1-20) 355 🔴 450 🔴 458 🔴 19
STSO 1020 steps (101-120) 306 🔴 366 🔴 402 🔴 19
STSO 1020 steps (1001-1020) 611 🔴 701 🔴 728 🔴 19
WO 1020 steps 434124 434124 434124 1
SL stream latency 169 🔴 206 🔴 234 🔴 30

8d92b85

Mon, 20 Jul 2026 19:32:09 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 1409 🔴 1428 🔴 1586 🔴 30
TTFS stream 1401 🔴 1438 🔴 1978 🔴 30
TTFS hook + stream 1694 🔴 1726 🔴 2009 🔴 30
STSO 1020 steps (1-20) 268 🔴 307 🔴 309 🔴 19
STSO 1020 steps (101-120) 344 🔴 417 🔴 521 🔴 19
STSO 1020 steps (1001-1020) 564 🔴 613 🔴 696 🔴 19
WO 1020 steps 414896 414896 414896 1
SL stream latency 192 🔴 231 🔴 300 🔴 30

5062c00

Mon, 20 Jul 2026 18:46:24 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 1266 🔴 1279 🔴 1333 🔴 30
TTFS stream 1280 🔴 1290 🔴 1316 🔴 30
TTFS hook + stream 1479 🔴 1522 🔴 1606 🔴 30
STSO 1020 steps (1-20) 311 🔴 488 🔴 524 🔴 19
STSO 1020 steps (101-120) 332 🔴 429 🔴 638 🔴 19
STSO 1020 steps (1001-1020) 561 🔴 669 🔴 674 🔴 19
WO 1020 steps 416504 416504 416504 1
SL stream latency 175 🔴 213 🔴 402 🔴 30

310f227

Fri, 17 Jul 2026 19:14:49 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS stream 1699 🔴 1733 🔴 3652 🔴 30
TTFS hook + stream 1943 🔴 2031 🔴 3686 🔴 30
STSO 1020 steps (1-20) 356 🔴 398 🔴 470 🔴 19
STSO 1020 steps (101-120) 308 🔴 405 🔴 555 🔴 19
STSO 1020 steps (1001-1020) 764 🔴 773 🔴 808 🔴 19
WO stream 1699 1733 3652 30
WO hook + stream 1943 2031 3686 30
SL stream 5806 🔴 5933 🔴 6050 🔴 30
SL hook + stream 5648 🔴 5729 🔴 6639 🔴 30

330a548

Fri, 17 Jul 2026 16:29:55 GMT · run logs

vercel / nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS stream 1721 🔴 1783 🔴 1905 🔴 30
TTFS hook + stream 2064 🔴 2121 🔴 2384 🔴 30
STSO 1020 steps (1-20) 333 🔴 436 🔴 521 🔴 19
STSO 1020 steps (101-120) 491 🔴 581 🔴 616 🔴 19
STSO 1020 steps (1001-1020) 938 🔴 999 🔴 1100 🔴 19
WO stream 1721 1783 1905 30
WO hook + stream 2064 2121 2384 30
SL stream 5877 🔴 6059 🔴 6309 🔴 30
SL hook + stream 5761 🔴 5825 🔴 7096 🔴 30

Best/P75/P90/P99 deltas compare against the most recent benchmark run on main at the time of this run. 🔻 flags a delta worse than +15%, 💚 one better than −15%.

Metrics — TTFS: time to first step body (in-deployment start() → first step body, deployment clocks) · STSO: step-to-step overhead (gap between consecutive step bodies) · WO: workflow overhead (whole-run time outside step bodies, in-deployment anchored) · SL: stream latency (in-deployment write → read propagation, readAt - writtenAt)

Scenarios — step: one trivial no-op step, no stream; no hooks, so the run stays in turbo mode (in-process fast path) · stream: one streaming step; no hooks, so the run stays in turbo mode (in-process fast path) · hook + stream: registers a hook before one step, which exits turbo mode (dispatch path) · 1020 steps: 1020 trivial sequential steps; STSO is measured between consecutive steps in the given step ranges, and WO is the whole-run overhead outside step bodies · stream latency: parallel reader/writer steps on a dedicated stream; SL is the in-deployment write->read propagation (readAt - writtenAt)

🔴 marks a percentile over its target (within target is left unmarked). Targets (p75/p90/p99, ms) — TTFS 200/300/600 · SL 50/60/125 · STSO (1-20) 20/30/60 · STSO (101-120) 30/45/90 · STSO (1001-1020) 40/60/120

All metrics are measured from deployment-side timestamps only. Runs are triggered by an in-deployment route that stamps the anchor (clientStart) right before start(), so the CI runner’s request and its path through api.vercel.com sit outside every measured window. TTFS = in-deployment start() → first step body (turbo uses the in-process fast path, non-turbo the dispatch path), and includes the VQS dispatch hop plus any /flow cold start. STSO/WO are measured between step bodies on the deployment. SL is measured inside the workflow (parallel reader/writer steps), so it no longer includes the api.vercel.com read path.

Cold starts are kept in the numbers on purpose — they are part of real bursty-workload latency. The workbench deployment cold-starts the /flow invocation for a large fraction of runs, inflating P75+; the Best column shows the fastest (warm-start) sample for comparison.

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

All tests passed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 1455 0 239 1694
✅ 💻 Local Development 1621 0 227 1848
✅ 📦 Local Production 1621 0 227 1848
✅ 🐘 Local Postgres 1621 0 227 1848
✅ 🪟 Windows 154 0 0 154
✅ 📋 Other 1020 0 212 1232
✅ vercel-multi-region 27 0 0 27
Total 7519 0 1132 8651

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 126 0 28
✅ example 126 0 28
✅ express 126 0 28
✅ fastify 126 0 28
✅ hono 126 0 28
✅ nextjs-turbopack 151 0 3
✅ nextjs-webpack 151 0 3
✅ nitro 126 0 28
✅ nuxt 126 0 28
✅ sveltekit 145 0 9
✅ vite 126 0 28
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 128 0 26
✅ express-stable 128 0 26
✅ fastify-stable 128 0 26
✅ hono-stable 128 0 26
✅ nextjs-turbopack-canary 135 0 19
✅ nextjs-turbopack-stable 154 0 0
✅ nextjs-webpack-canary 135 0 19
✅ nextjs-webpack-stable 154 0 0
✅ nitro-stable 128 0 26
✅ nuxt-stable 128 0 26
✅ sveltekit-stable 147 0 7
✅ vite-stable 128 0 26
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 154 0 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 128 0 26
✅ e2e-local-dev-tanstack-start- 128 0 26
✅ e2e-local-postgres-nest-stable 128 0 26
✅ e2e-local-postgres-tanstack-start- 128 0 26
✅ e2e-local-prod-nest-stable 128 0 26
✅ e2e-local-prod-tanstack-start- 128 0 26
✅ e2e-vercel-prod-nest 126 0 28
✅ e2e-vercel-prod-tanstack-start 126 0 28
✅ vercel-multi-region
App Passed Failed Skipped
✅ nextjs-turbopack 27 0 0

📋 View full workflow run

@shalabhc
shalabhc force-pushed the shalabhc/event-limit-enforcement branch from 4d4aefc to d4ddf7e Compare July 17, 2026 16:07
@shalabhc
shalabhc force-pushed the shalabhc/event-limit-enforcement branch from d4ddf7e to 330a548 Compare July 17, 2026 16:10
@vercel
vercel Bot temporarily deployed to Preview – workflow-docs July 17, 2026 16:10 Inactive
Comment thread workbench/nextjs-turbopack/workflows/test_blob_violation.ts Outdated
@shalabhc

Copy link
Copy Markdown
Collaborator Author

Made change to use server provided limit.
Refactored to raise a new max events exceeded error that gets caught and fails run via a prexisting catch.

@VaguelySerious VaguelySerious left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait with merge until other PRs merge first

Comment thread packages/world/src/events.ts Outdated
Comment thread packages/world-testing/workflows/event-limit.ts Outdated

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

workbench/nest's vercel-build script invokes packages/nest/dist/cli.js without first compiling the @workflow/nest workspace dependency, so the file is missing and the build aborts with MODULE_NOT_FOUND.

Fix on Vercel

@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

You must have Developer access to commit code to Vercel Labs on Vercel. If you contact an administrator and receive Developer access, commit again to see your changes.

Learn more: https://vercel.com/docs/accounts/team-members-and-roles/access-roles#team-level-roles

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #3042. Merge conflicts were resolved by AI — please review carefully. (backport job run)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants